using System.Collections;
using Holoville.HOTween;
using UnityEngine;

public class AnimationArrow : MonoBehaviour
{
	[SerializeField]
	private bool disable = true;

	[SerializeField]
	private float disableTime = 4f;

	public Vector3 direction;

	[HideInInspector]
	public float duration = 1f;

	private Vector3? _startPosition;

	private bool _deActive;

	[SerializeField]
	private bool useTimeScaleIndependentUpdate = true;

	private void Awake()
	{
		Vector3? startPosition = _startPosition;
		if (!startPosition.HasValue)
		{
			_startPosition = base.transform.localPosition;
		}
		HOTween.Init();
	}

	private void OnEnable()
	{
		_deActive = false;
		if (disable)
		{
			StartCoroutine(WaitAnimation());
		}
		Transform obj = base.transform;
		Vector3? startPosition = _startPosition;
		obj.localPosition = startPosition.Value;
		AnimationBot();
	}

	private void OnDisable()
	{
		StopAllCoroutines();
		HOTween.Kill(base.transform);
	}

	private IEnumerator WaitAnimation()
	{
		yield return new WaitForSeconds(disableTime);
		base.gameObject.SetActive(false);
		_deActive = true;
		HOTween.Kill(base.transform);
	}

	private void AnimationBot()
	{
		if (!_deActive)
		{
			Vector3 vector = base.transform.localPosition - direction;
			HOTween.Kill(base.transform);
			if (useTimeScaleIndependentUpdate)
			{
				HOTween.To(base.transform, duration, new TweenParms().Prop("localPosition", vector).OnComplete(AnimationTop).UpdateType(UpdateType.TimeScaleIndependentUpdate));
			}
			else
			{
				HOTween.To(base.transform, duration, new TweenParms().Prop("localPosition", vector).OnComplete(AnimationTop));
			}
		}
	}

	private void AnimationTop()
	{
		if (!_deActive)
		{
			Vector3 vector = base.transform.localPosition + direction;
			HOTween.Kill(base.transform);
			if (useTimeScaleIndependentUpdate)
			{
				HOTween.To(base.transform, duration, new TweenParms().Prop("localPosition", vector).OnComplete(AnimationBot).UpdateType(UpdateType.TimeScaleIndependentUpdate));
			}
			else
			{
				HOTween.To(base.transform, duration, new TweenParms().Prop("localPosition", vector).OnComplete(AnimationBot));
			}
		}
	}
}
